#!/bin/sh

set -ex
gif1="${1}"
shift 1
gif2="${1}"
shift 1
gif3="${1}"
shift 1
gif4="${1}"
shift 1
out="${1}"
shift 1
set +e

# https://ottverse.com/stack-videos-horizontally-vertically-grid-with-ffmpeg/
exec ffmpeg \
-i "$gif1" -i "$gif2" -i "$gif3" -i "$gif4" \
-filter_complex \
"[0:v][1:v]hstack=inputs=2[top]; \
[2:v][3:v]hstack=inputs=2[bottom]; \
[top][bottom]vstack=inputs=2[v]" \
-map "[v]" \
"$out" "$@"
